﻿package code {
	// class acts as a vertex that stores two points
	// based off of schwartz code
	public class Vertex {
		public var x:Number;
		public var y:Number;
		
		public function Vertex(x:Number, y:Number) {
			this.x = x;
			this.y = y;
		}
		
		// adds two vertices together
		public static function add(p:Vertex,q:Vertex):Vertex {
			return new Vertex(p.x+q.x,p.y+q.y);
		}
		
		// subtracts two vertices from each other
		public static function sub(p:Vertex,q:Vertex):Vertex {
			return new Vertex(q.x-p.x,q.y-p.y);
		}
		
		// calculates displacement of two vertices using sqrt((y2 - y1) ^ 2 + (x2 - x2) ^ 2)
		public static function displace(p:Vertex, q:Vertex):Number{
			return Math.sqrt(Math.pow((q.y - p.y), 2) + Math.pow((q.x - p.x), 2));
		}
		
		// gets magnitude of a vertex using sqrt(x ^ 2 + y ^ 2)
		public static function getMagnitude(p:Vertex):Number{
			return Math.sqrt((p.x * p.x) + (p.y * p.y));
		}
		
		public function toString():String {
			return "("+x+","+y+")";
			
		}

	}
	
}
